﻿using System;
using System.Data;
using System.Linq;
using System.Web.Services.Protocols;
using System.Web.UI;
using System.Web.UI.WebControls;
using MedicWeb.MedicService;

namespace MedicWeb.forms.Print.Edit
{
    public partial class ExtractEdit : SessionPage {

        protected void Page_Load(object sender, EventArgs e) {

            //for (int i = 0; i < edtBody.Controls.Count; i++) {
            //    Control control = edtBody.Controls[i];
            //    if (control.Controls != null) {
            //        for (int j = 0; j < control.Controls.Count; j++) {
            //            Control control1 = control.Controls[j];
            //        }
            //    }
            //}
            Control findControl = edtBody.FindControl("ctl01");
            
            string s = Request.QueryString["id"];
            int id = s == null ? 0 : int.Parse(s);

                var ms = new MainService();
                if (id > 0) {
                    //printTemplateExtract = ms.LoadPrintTemplateExtract(GetSession(), id);
                }else {
                    //printTemplateExtract = new PrintTemplateExtract();
                }

            if (!IsPostBack) {
                //tfTitle.Text = printTemplateExtract.Title;
                //edtBody.Content = printTemplateExtract._body;
                //edtSecond.Content = printTemplateExtract._second;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try {
                var ms = new MainService();
                //printTemplateExtract._body = edtBody.Content;
                //printTemplateExtract._second = edtSecond.Content;
                //printTemplateExtract.Title = tfTitle.Text;
                //ms.SavePrintTemplateExtract(GetSession(), printTemplateExtract);

                Session["success"] = "Изменения сохранены успешно";
            } catch (Exception ex) {

                if (ex.InnerException is SoapException
                    && ((SoapException) ex.InnerException).Detail.InnerText == "AuthorizationException") {
                    throw ex;
                } else {
                    Session["error"] = "Ошибка сохранения";
                }
            }
        }
    }
}